﻿using Microsoft.VisualStudio.DebuggerVisualizers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Xml.Linq;

namespace FR.CodeVisualizer.ObjectSource
{
    public class XDoccumentVisualizerObjectSource : VisualizerObjectSource
    {
        public override void TransferData(object target, System.IO.Stream incomingData, System.IO.Stream outgoingData)
        {
            if (target is XDocument)
            {
                string newXML = StreamSerializer.StreamToObject(incomingData) as string;
                XDocument newDoc = XDocument.Parse(newXML);

                target = newDoc;
            }
        }

        public override void GetData(object target, System.IO.Stream outgoingData)
        {
            if (target != null)
            {
                if (target is XDocument)
                    StreamSerializer.ObjectToStream(outgoingData, (target as XDocument).ToString());
            }
        }
    }
}
